﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
namespace DoAn
{
    public partial class frCDHTTT : Form
    {
        public frCDHTTT()
        {
            InitializeComponent();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtTenHTTT.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập tên HTTT.", "Lỗi");
                return;
            }
            HTTTBUS ht = new HTTTBUS();
            if(ht.KtHTTT(txtTenHTTT.Text) == false)
            {
                MessageBox.Show("Hình thức thanh toán này đã tồn tại.", "Lỗi");
                return;
            }                        
            ht.ThemHTTT(txtTenHTTT.Text);
            txtTenHTTT.Text = "";
            XuatHTTT();            
        }
        private void XuatHTTT()
        {
            HTTTBUS ht = new HTTTBUS();
            List<HTTTDTO> listht = new List<HTTTDTO>();
            listht = ht.LayHTTT();
            gvHTTT.Rows.Clear();
            for (int i = 0; i < listht.Count; i++)            
                gvHTTT.Rows.Add(i + 1, listht[i].TenHTTT);            
        }

        private void frCDHTTT_Load(object sender, EventArgs e)
        {
            XuatHTTT();
        }

        private void txtTenHTTT_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnThem_Click(sender, e);
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (txtTenHTTT.Text == "")
                MessageBox.Show("Bạn chưa nhập tên HTTT.", "Lỗi");
            else
            {
                HTTTBUS ht = new HTTTBUS();
                ht.SuaHTTT(txtTenHTTT.Text, gvHTTT.CurrentRow.Cells[1].Value.ToString());
                XuatHTTT();
            }
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            HTTTBUS ht = new HTTTBUS();            
            ht.XoaHTTT(gvHTTT.CurrentRow.Cells[1].Value.ToString());
            XuatHTTT();
        }        
    }
}
